var WebApp = {
    callbackIndex: 0,
    callbackArray: new Array(),
    JSCallBack: function (i, json) {
        try {
            console.log('索引:' + i);
            console.log(this.callbackArray);
            var callBack = this.getCallback(i);
            console.log(json);
            console.log(callBack);
            callBack(json.indexOf('\'') != -1 ? json.replace(/"/g, '\\"').replace(/'/g, '"') : json);
        } catch (e) {
            console.log('使用$1');
            console.log(e);
            try {
                callBack.$1(json.indexOf('\'') != -1 ? json.replace(/"/g, '\\"').replace(/'/g, '"') : json);
            } catch (e1) {
                console.log(e1);
            }
        }
    },

    saveCallback: function (a) {
        var index = this.callbackIndex;
        this.callbackArray[index] = a;
        this.callbackIndex++;
        return index;
    },

    getCallback: function (i) {
        return this.callbackArray[i]
    },
    invoke: function (success, failed) {
        var si = this.saveCallback(success);
        var fi = this.saveCallback(failed);
        window.nativePlugin.invoke(si, fi);
    }
}
